Skip to content

Handle geojson layers like other layers#605

Draft
digitaltom wants to merge 18 commits intomainfrom
unify_layer_handling
Draft

Handle geojson layers like other layers#605
digitaltom wants to merge 18 commits intomainfrom
unify_layer_handling

Conversation

@digitaltom
Copy link
Collaborator

No description provided.

Copilot AI review requested due to automatic review settings February 2, 2026 23:34
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors MapLibre layer handling so GeoJSON layers are treated similarly to other layer types (separate sources/styles per layer) and introduces layer-level flags intended to control clustering/heatmap behavior.

Changes:

  • Introduces per-layer GeoJSON sources (<type>-source-<layerId>) and new feature lookup helpers in maplibre/layers/layers.js.
  • Updates various MapLibre modules/controllers to use the new feature lookup approach instead of geojsonData.
  • Adds a Wikipedia marker icon and extends Layer summaries with heatmap/cluster flags.

Reviewed changes

Copilot reviewed 11 out of 12 changed files in this pull request and generated 14 comments.

Show a summary per file
File Description
public/icons/wikipedia.png Adds an icon used by the Wikipedia layer features.
app/models/layer.rb Adds heatmap/cluster fields and includes them in serialized layer summaries.
app/javascript/maplibre/undo.js Starts migration away from geojsonData imports (but still needs further refactor).
app/javascript/maplibre/styles.js Updates style initialization and heatmap layer handling; switches feature lookup to getFeature.
app/javascript/maplibre/routing/osrm.js Switches route feature lookup to getFeature.
app/javascript/maplibre/map.js Removes global geojsonData usage patterns and shifts rendering toward per-layer sources.
app/javascript/maplibre/layers/layers.js Initializes per-layer GeoJSON sources/styles and adds getFeature/getFeatures/hasFeatures.
app/javascript/maplibre/feature.js Uses new feature access helpers for edit gating and derived-feature generation inputs.
app/javascript/maplibre/edit.js Uses new helpers for “untouched map” logic and URL-based selection.
app/javascript/maplibre/controls/shared.js Updates feature list items to reference the new per-layer source names.
app/javascript/controllers/feature/modal_controller.js Refactors selected-feature access (now needs getFeature import).
app/javascript/controllers/feature/edit_controller.js Refactors edit-feature access (now needs getFeature import).
Comments suppressed due to low confidence (1)

app/javascript/maplibre/map.js:123

  • initializeMap highlights a URL-selected feature via highlightFeature(feature, true) without passing the feature’s source. Since the default source in highlightFeature is geojson-source (which is no longer created), setFeatureState will fail or highlight the wrong source. Determine the correct source for the feature (e.g., from the owning layer) and pass it explicitly.
    const urlFeatureId = new URLSearchParams(window.location.search).get('f')
    let feature = getFeature(urlFeatureId)
    if (feature) {
      resetControls()
      highlightFeature(feature, true)
      const center = centroid(feature)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 407 to 413
// updateData requires a 'GeoJSONSourceDiff', with add/update/remove lists
map.getSource('geojson-source').setData(renderedGeojsonData())
//map.getSource('geojson-source').setData(renderedGeojsonData())
console.log('layers:', layers)
layers.filter(f => f.type !== 'geojson').forEach((layer) => {
layers.forEach((layer) => {
if (layer.geojson) {
console.log("Setting layer data", layer.type, layer.id, layer.geojson)
map.getSource(layer.type + '-source-' + layer.id).setData(layer.geojson, false)
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redrawGeojson() no longer calls renderedGeojsonData() and instead pushes layer.geojson directly into each source. This drops the side effects of renderedGeojsonData() (km-marker source updates via renderKmMarkers() and extrusion polygons via renderExtrusionLines()), so km markers / extrusions will stop rendering/updating. Re-introduce those steps in the new per-layer rendering flow (and ensure derived features are included in the appropriate source data).

Copilot uses AI. Check for mistakes.
const feature = geojsonData.features.find(f => f.id === targetId)
const feature = getFeature(targetId)
if (feature) {
flyToFeature(feature)
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When handling onclick-target navigation, flyToFeature(feature) is called without a source. flyToFeature defaults to geojson-source, which no longer exists for per-layer sources, so the follow-up highlight will fail. Pass sourceName (or otherwise resolve the owning source) into flyToFeature.

Suggested change
flyToFeature(feature)
flyToFeature(feature, sourceName)

Copilot uses AI. Check for mistakes.
Comment on lines 34 to +37
map.addLayer(setSource(styles()[styleName], sourceName))
})
if (heatmap) { map.addLayer(setSource(styles()['heatmap-layer'], sourceName)) }
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

initializeViewStyles now only adds the heatmap layer when heatmap=true, but existing callers (e.g. overpass layer initialization) invoke it with a single argument. This change will disable rendering for existing heatmap=true overpass queries unless those call sites are updated to pass the flag.

Copilot uses AI. Check for mistakes.
Comment on lines 19 to 20
addGeoJSONSource('geojson-source-' + layer.id, false)
initializeViewStyles('geojson-source-' + layer.id)
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GeoJSON layers are always initialized with cluster=false and without passing the new heatmap flag into initializeViewStyles. Since layer summaries now include cluster/heatmap, these settings appear intended to be configurable but are currently ignored. Consider wiring layer.cluster into addGeoJSONSource(...) and layer.heatmap into initializeViewStyles(..., layer.heatmap).

Suggested change
addGeoJSONSource('geojson-source-' + layer.id, false)
initializeViewStyles('geojson-source-' + layer.id)
addGeoJSONSource('geojson-source-' + layer.id, Boolean(layer.cluster))
initializeViewStyles('geojson-source-' + layer.id, Boolean(layer.heatmap))

Copilot uses AI. Check for mistakes.
let feature = getFeature(prevState.state.id, 'geojson')
if (feature) {
addRedoState(prevState.type, feature)
feature = prevState.state
@digitaltom digitaltom marked this pull request as draft February 5, 2026 23:40
import { layers } from 'maplibre/map'
import { addGeoJSONSource, map } from 'maplibre/map'
import { initializeGeoJSONLayers } from 'maplibre/layers/geojson'
import { initializeKmMarkerStyles } from 'maplibre/feature'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant